<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Builder模式+Proxy</title>
</head>
<body>
<script>
    /*构建者模式*/
    //以学生类为例子
    class Student {
        //把属性变做私有的
        _id = 0;
        _name = '向妙';
        _sex = '女';

        get id() {
            return this._id;
        }

        get name() {
            return this._name;
        }

        get sex() {
            return this._sex;
        }

//返回一个指针
        static getAInstance() {
            let proxy = new Proxy(this, {
                set(target, p, value, receiver) {
                },
                get(target, p, receiver) {
                }
            });
            return this === null ? proxy : this;
        }

        static Builder = {
            //方法：拿到对象指针
            getSingleton: function () {
                //这样就不用实例化
                return Person.getAInstance();
            },
            //填充属性
            buildId: function (id) {
                this.getSingleton.id = id;
                return this;
            },
            //填充属性
            buildName: function (name) {
                this.getSingleton.name = name;
                return this;
            },
            //填充属性
            buildSex: function (sex) {
                this.getSingleton.sex = sex;
                return this;
            },
            getCur: function () {
                return new Person(this.getSingleton());
            }
        };
    }

    //建造者
    Student.Builder.buildName('');
    console.log(builder);
</script>
</body>
</html>